/*
 * @Description: 自增字段reducer
 * @Author: Rfan
 * @Date: 2022-01-08 16:30:05
 * @LastEditTime: 2022-10-31 20:11:33
 */

import {
  SET_COMMON_RULES,
  SET_SELECT_AT,
  SET_SELECT_FOND,
  SET_SELECT_LEVEL,
  SET_SELECT_INCREASE_LIST
} from '../constants';

export const AutoIncreaseReducer = (state, action) => {
  switch (action.type) {
    // 表格加载loading
    case SET_SELECT_FOND:
      return {
        ...state,
        selectFond: action.data
      };

    // 设置选中的档案类型
    case SET_SELECT_AT:
      return {
        ...state,
        selectAT: action.data
      };

    /**
     * @description: 设置选中的层级
     * @param {object} data 选中的层级
     */
    case SET_SELECT_LEVEL:
      return {
        ...state,
        selectLevel: action.data
      };

    // 设置排序列表
    case SET_SELECT_INCREASE_LIST: {
      const _data = action.data || {};
      const info = {
        list: _data.fieldList
      };
      if (_data.fieldList.length > 0) {
        info.commonRule = {
          serialLength: _data.serialLength
        };
      }
      return {
        ...state,
        ...info,
        loading: false
      };
    }

    /**
     * @description: 分组排列规则
     * @param {object} data 选中的层级
     */
    case SET_COMMON_RULES: {
      return {
        ...state,
        commonRule: action.data
      };
    }

    default:
      console.log('untouched', action);
      return state;
  }
};
